package imp

/**
  * 隐式转换函数
  */
object ImplicitFunction extends App {

  class Dog(val name: String) {
    def bark(): Unit = println(s"$name say: wang.")
  }

  implicit def double2int(d: Double): Int = d.toInt

  implicit def string2Dog(s: String): Dog = new Dog(s)

  // 1.1是double类型，通过double2int函数，隐式转换成int，赋值给int类型变量f
  val f: Int = 1.1
  println(f)

  // string类型没有bark方法，Dog类型才有bark方法，幸好有string类型到Dog类型的隐式转换
  "Teddy".bark()
}
